// 将各种message modules 汇总到这里

let language = {};
try {
  // require.context(要搜索的文件夹目录,是否还应该搜索它的子目录,以及一个匹配文件的正则表达式)
  const context = require.context('./language', true, /\/.*\.js$/)
  context.keys().forEach((key) => {
    let catalogArray = key.split('/')
    // 拿到对应的语言类型，如en、zh_CN
    const type = catalogArray[1]
    if (!language.hasOwnProperty(type)) {
      language[type] = {}
    }
    catalogArray = catalogArray.slice(2,catalogArray.length)
    if (!language[type].hasOwnProperty(catalogArray[0])) {
      language[type][catalogArray[0]] = {}
    }
    const len = catalogArray.length - 1
    let fileName = catalogArray[len]
    const lastIndex = fileName.lastIndexOf('.')
    catalogArray[len] = fileName.substring(0, lastIndex)
    language[type][catalogArray[0]][catalogArray[1]] = context(key)
  })
} catch (e) {
  throw new Error('i18n国际化加载错误：' + e)
}

export default language;
